From bd7f7849f297065258f265a03812058d981ffcb4 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Thu, 14 Jul 2011 13:22:36 +0100 Subject: [PATCH] libxl: IDL: refactor code to massage a type into a function argument Signed-off-by: Ian Campbell Committed-by: Ian Jackson --- tools/libxl/gentypes.py | 7 +------ tools/libxl/libxltypes.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py index 6d798738f2..4d108f8421 100644 --- a/tools/libxl/gentypes.py +++ b/tools/libxl/gentypes.py @@ -84,11 +84,6 @@ def libxl_C_type_destroy(ty, v, indent = " ", parent = None): else: deref = v + "." - if ty.passby == libxltypes.PASS_BY_REFERENCE and parent is not None: - makeref = "&" - else: - makeref = "" - s = "" if isinstance(ty, libxltypes.KeyedUnion): if parent is None: @@ -107,7 +102,7 @@ def libxl_C_type_destroy(ty, v, indent = " ", parent = None): s += libxl_C_type_destroy(f.type, deref + f.name, "", deref) else: if ty.destructor_fn is not None: - s += "%s(%s);\n" % (ty.destructor_fn, makeref + v) + s += "%s(%s);\n" % (ty.destructor_fn, ty.pass_arg(v, parent is None)) if s != "": s = indent + s diff --git a/tools/libxl/libxltypes.py b/tools/libxl/libxltypes.py index 29336d4a55..25430e262d 100644 --- a/tools/libxl/libxltypes.py +++ b/tools/libxl/libxltypes.py @@ -50,6 +50,21 @@ class Type(object): else: return "%s %s" % (self.typename, n) + def pass_arg(self, n, isref=None, passby=None): + if passby is None: passby = self.passby + if isref is None: isref = self.passby == PASS_BY_REFERENCE + + if passby == PASS_BY_REFERENCE: + if isref: + return "%s" % (n) + else: + return "&%s" % (n) + else: + if isref: + return "*%s" % (n) + else: + return "%s" % (n) + class Builtin(Type): """Builtin type""" def __init__(self, typename, **kwargs): -- 2.30.2